<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/common/common.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8">
  <title>layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="<%=path %>/layui/css/layui.css">
  <link rel="stylesheet" href="<%=path %>/layui/css/lxq.css">
    <script type="text/javascript" src="<%=path %>/layui/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="<%=path %>/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=path %>/layui/util.js" charset="utf-8"></script>
</head>
<body>
<div class="lxq-body">
	<div class="layui-row lxq-address">
		位置：个人中心>联系人管理
		<hr>
	</div>





  <div class="layui-row layui-col-space10">
   <div class="layui-col-xs6">
   <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>联系人列表</legend>
	</fieldset>
   		  联系人编号：
		  <div class="layui-inline">
		    <input class="layui-input" name="infoName" id="academy_name" autocomplete="off">
		  </div>
		  <button class="layui-btn" data-type="search">搜索</button><button class="layui-btn" data-type="add">添加</button>
		  
		  
      <table class="layui-hide" id="friendTable" lay-filter="friendTable"></table> 
   </div>
    <div class="layui-col-xs6">
       <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
 		 <legend>联系人集合</legend>
		</fieldset>
    		<button class="layui-btn" data-type="addUser">添加个人</button>
    		<button class="layui-btn" data-type="addClass">添加班级</button>
    		<button class="layui-btn" data-type="addMajor">添加专业</button>
    		<button class="layui-btn" data-type="addAcademy">添加学院</button>
    		<button class="layui-btn" data-type="addUnit">添加部门</button>
		  
      <table class="layui-hide" id="branchTable" lay-filter="branchTable"></table> 
   </div>
 
	</div>

 		

</div>              
          

 
<script>
layui.use(['table'], function(){
  var table = layui.table;
  
  //加载联系人列表
  table.render({
	    elem: '#friendTable'
	    ,url:'<%=basePath %>/biz/Branch_getFriend'
	    ,page: true
	    ,cols: [[
   	      {field:'userId',  title: 'ID', sort: true}
	      ,{field:'userName',  title: '姓名'}
	      ,{field:'userType', title: '用户类型', templet:'<div>{{ Situation(d.userType,"0,1,9","学生,教师,管理员")}}</div>'}
	      ,{field:'userAcademy', title: '学院'}
	      ,{field:'userMajor', title: '专业'}
	      ,{field:'userClass', title: '班级'}
	      ,{field:'userUnit', title: '部门'}
	    ]]
 		 ,id: 'friendTable'
	  });
  
  table.render({
	    elem: '#branchTable'
	    ,url:'<%=basePath %>/biz/Branch_getBranchSet'
	    ,page: true
	    ,cols: [[
 	      {field:'sonName',  title: '名'}
	      ,{field:'branchType', title: '类型', templet:'<div>{{ Situation(d.branchType,"0,1,2,3,4","个人,班级,专业,学院,部门")}}</div>'}
	      ,{fixed: 'right', title:'操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
		 ,id: 'branchTable'
	  });
  
  
	  //监听工具条
	  table.on('tool(branchTable)', function(obj){
	    var data = obj.data;
		if(obj.event === 'del'){
	      layer.confirm('真的删除行么', function(index){
	        obj.del();
	        $.post('<%=basePath %>/biz/Branch_del',{"id":data.id},function(){});
	        layer.close(index);
	      });
	    } 
	  });
	  
  	
  //事件触发	
  	var $ = layui.$, active = {
  		addUnit: function(){
  	    	  layer.open({
  	    		  title: '添加部门',
  	    		  type: 2, 
  	    		  area: ['50%', '90%'],
  	    		  content: '<%=basePath%>/biz/Branch_toAddUnit',
  	    		  end : function(layero, index){
  	    			  reloadSet();
  	    		  }
  	    	  });
  	    },
  		addUser: function(){
  	    	  layer.open({
  	    		  title: '添加用户',
  	    		  type: 2, 
  	    		  area: ['80%', '90%'],
  	    		  content: '<%=basePath%>/biz/Branch_toAddUser',
  	    		  end : function(layero, index){
  	    			 reloadSet();
  	    		  }
  	    	  });
  	    },
	    addAcademy: function(){
	    	  layer.open({
	    		  title: '添加学院',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=basePath%>/biz/Branch_toAddAcademy',
	    		  end : function(layero, index){
	    			  reloadSet();
	    		  }
	    	  });
	    },
	    
	    addMajor: function(){
	    	  layer.open({
	    		  title: '添加专业',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=basePath%>/biz/Branch_toAddMajor',
	    		  end : function(layero, index){
	    			  reloadSet();
	    		  }
	    	  });
	    },
	    
	    addClass: function(){
	    	  layer.open({
	    		  title: '添加班级',
	    		  type: 2, 
	    		  area: ['50%', '90%'],
	    		  content: '<%=basePath%>/biz/Branch_toAddClass',
	    		  end : function(layero, index){
	    			  reloadSet();
	    		  }
	    	  });
	    }
 
	};
  
    function reloadSet(){
        table.reload("friendTable",{
      	  url:'<%=basePath %>/biz/Branch_getFriend'
            ,page: {
              curr: 1 //重新从第 1 页开始
            }
        });
        
        table.reload("branchTable",{
        	  url:'<%=basePath %>/biz/Branch_getBranchSet'
              ,page: {
                curr: 1 //重新从第 1 页开始
              }
          });
    }
	  
	  $('.layui-btn').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
		//监听动态元素
	    $('.active').on('click','.layui-btn', function () {
		    var type = $(this).data('type');
		    active[type] ? active[type].call(this) : '';
	    });
  
});
</script>



    <script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
	</script>

</body>
</html>